package com.example.administrator.ygddriver.order.outorder;

import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.administrator.ygddriver.R;

import java.util.List;

public class OutOrderAdapter extends BaseQuickAdapter<ToSendRequestBean.ResultBean, BaseViewHolder> {
    private String place;

    public String getPlace() {
        return place;
    }

    public void setPlace(String place) {
        this.place = place;
    }

    public OutOrderAdapter(int layoutResId, @Nullable List<ToSendRequestBean.ResultBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ToSendRequestBean.ResultBean item) {
        ImageView imageView = helper.getView(R.id.item_fragment_out_order_status_iv);
        LinearLayout linearLayout = helper.getView(R.id.item_fragment_out_order_distance_ll);
        TextView profitsTv = helper.getView(R.id.item_fragment_out_order_profits_tv);
        TextView shippingTv = helper.getView(R.id.item_fragment_out_order_shippingstatus_tv);
        helper.setText(R.id.item_fragment_out_order_address_tv, item.getC_address());
        helper.setText(R.id.item_fragment_out_order_parcel_number_tv, "共" + item.getC_parcelnumber() + "件");
        helper.setText(R.id.item_fragment_out_order_waybill_number_tv, item.getC_waybillnumber() + "个运单");

        helper.setText(R.id.item_fragment_out_order_name_tv, item.getC_name());
        helper.setText(R.id.item_fragment_out_order_new_tv, place);
        Glide.with(mContext).load(item.getC_headportrait()).into((ImageView) helper.getView(R.id.item_fragment_out_order_head_portrait_iv));
        linearLayout.setVisibility(View.VISIBLE);
        shippingTv.setVisibility(View.INVISIBLE);
        profitsTv.setVisibility(View.GONE);
        if (item.getC_status().equals("2")) {
            imageView.setImageDrawable(mContext.getResources().getDrawable((R.mipmap.missed)));
            helper.setText(R.id.item_fragment_out_order_distance_tv, item.getC_distance() + "公里");
        } else if (item.getC_status().equals("3")) {
            imageView.setImageDrawable(mContext.getResources().getDrawable((R.mipmap.have_access)));
            helper.setText(R.id.item_fragment_out_order_distance_tv, item.getC_distance() + "公里");
        } else if (item.getC_status().equals("4")) {
            linearLayout.setVisibility(View.GONE);
            profitsTv.setVisibility(View.VISIBLE);
            shippingTv.setVisibility(View.VISIBLE);
            imageView.setImageDrawable(mContext.getResources().getDrawable((R.mipmap.delivery)));
            if (item.getC_shippingstatus().equals("4")) {
                helper.setText(R.id.item_fragment_out_order_profits_tv, "已到账");
                helper.setText(R.id.item_fragment_out_order_shippingstatus_tv, "已赚取佣金" + item.getC_driver_profits() + "元");
            } else if (item.getC_shippingstatus().equals("3")) {
                helper.setText(R.id.item_fragment_out_order_shippingstatus_tv, item.getC_driver_profits());
                helper.setText(R.id.item_fragment_out_order_profits_tv, "即将到账");
                helper.setText(R.id.item_fragment_out_order_shippingstatus_tv, "即将获得佣金" + item.getC_driver_profits() + "元");
            } else if (item.getC_shippingstatus().equals("2")) {
                helper.setText(R.id.item_fragment_out_order_profits_tv, "已超时");
                helper.setText(R.id.item_fragment_out_order_shippingstatus_tv, "送达超时，无法获得利润");
            }

        }
        helper.addOnClickListener(R.id.item_fragment_out_order_status_ll);
        helper.addOnClickListener(R.id.item_fragment_out_order_phone_iv);
    }
}
